;
Ext.namespace('GBIF.GeoSpatial');

GBIF.GeoSpatial.Feature = function(config){
    
	this.geomap = new GBIF.GeoSpatial.MapComponent({
		width:500
	,	height:600	
	});
	
	
	this.tiled = new OpenLayers.Layer.WMS(
                    "cluster1 - Tiled", "http://ogc.gbif.org/wms",
                    {
                        width: '512',
                        srs: 'EPSG:4326',
						url:'http://ogc.gbif.org/wms',
                        layers: 'gbif:cluster1',
                        height: '457',
                        styles: '',
                        format: "image/png",
                        tiled: 'true',
						transparent:true,
						querable:true,
					    tilesOrigin : this.geomap.map.maxExtent.left + ',' + this.geomap.map.maxExtent.bottom
                    },
                    {
                        buffer: 0,
                        displayOutsideMaxExtent: true
                    } 
         );			
   /*         
   this.untiled = new OpenLayers.Layer.WMS(
        "cluster10 - Untiled", "http://ogc.gbif.org/wms",
            {
            	width: '512'
            ,	srs: 'EPSG:4326'
            ,   layers: 'gbif:cluster10'
            ,   height: '512'
            ,   styles: ''
            ,   format: 'image/png'
            }
			,   {
				singleTile: true, ratio: 1} 
            );
            
	this.tiled = new OpenLayers.Layer.WMS(
              "cluster10 - Tiled", "http://ogc.gbif.org/wms",
                    {
                        width: '512',
                        srs: 'EPSG:4326',
                        layers: 'gbif:cluster10',
                        height: '457',
                        styles: '',
                        format: "image/png",
                        tiled: 'true',
						transparent:true,
						querable:true,
					    tilesOrigin : this.geomap.map.maxExtent.left + ',' + this.geomap.map.maxExtent.bottom
                    },
                    {
                        buffer: 0,
                        displayOutsideMaxExtent: true
                    } 
         );	*/
			
      
    this.geomap.map.addLayers([this.tiled]);   
	
	this.geomap.map.events.register('click', this, function (e) {
				
	           	var params = {
	                    request: "GetFeatureInfo"
					,	version:'1.0.0'
                  //,   EXCEPTIONS: "application/vnd.ogc.se_xml",
                    ,   bbox: this.geomap.map.getExtent().toBBOX()
                    ,   x: e.xy.x
                    ,   y: e.xy.y
                    ,   info_format:'application/vnd.ogc.gml'
                    ,   query_layers: this.geomap.map.layers[1].params.LAYERS
                  //,   FEATURE_COUNT: 50
                    ,   srs: this.geomap.map.projection//'EPSG:4326'
                    ,   layers: this.geomap.map.layers[1].params.LAYERS
                    ,   styles: ''
                    ,   width: this.geomap.map.size.w
                    ,   height: this.geomap.map.size.h
                    ,   format: 'image/png'
				};
               OpenLayers.loadURL("../../resources/api/getfeatureinfo-proxy.php?url=http://ogc.gbif.org/wms", params, this, setHTML, setHTML);
               OpenLayers.Event.stop(e);
                });
				
	setHTML=function(response){
		var grid = Ext.getCmp('grid');
		var data = Ext.decode(response.responseText);
		var feature = [data.FeatureCollection.featureMember.cluster1];
		grid.store.loadData(feature);	
     };     
     
 	Ext.apply(this,config,{
			title: "Map"
        ,	height: 400
        ,	width: 600
        ,	items:[this.geomap]
	})
	
	
	
	
	GBIF.GeoSpatial.Feature.superclass.constructor.call(this, config)
}
Ext.extend(GBIF.GeoSpatial.Feature, Ext.Panel, {
	
})
